package com.logictech.lims.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.jeecgframework.p3.core.utils.common.PageList;
import org.jeecgframework.p3.core.utils.common.PageQuery;
import org.jeecgframework.p3.core.utils.common.Pagenation;
import org.springframework.stereotype.Service;

import com.logictech.lims.dao.PreparationInventoryDao;
import com.logictech.lims.dto.PreparationInventoryDto;
import com.logictech.lims.entity.PreparationInventory;
import com.logictech.lims.service.LogService;
import com.logictech.lims.service.PreparationInventoryService;

@Service("preparationInventoryService")
public class PreparationInventoryServiceImpl implements PreparationInventoryService {
	@Resource
	private PreparationInventoryDao preparationInventoryDao;
	
	@Resource
	private LogService logService;

	@Override
	public void doAdd(PreparationInventory preparationInventory) {
		preparationInventoryDao.add(preparationInventory);		
		logService.doAdd("1",preparationInventory);
	}

	@Override
	public void doEdit(PreparationInventory preparationInventory) {
		preparationInventoryDao.update(preparationInventory);
		logService.doAdd("2",preparationInventory);
	}

	@Override
	public void doDelete(String id) {
		logService.doAdd("3",preparationInventoryDao.get(id));
		preparationInventoryDao.delete(id);
	}

	@Override
	public PreparationInventoryDto queryById(String id) {
		PreparationInventoryDto preparationInventory  = (PreparationInventoryDto)preparationInventoryDao.get(id);
		return preparationInventory;
	}

	@Override
	public PageList<PreparationInventoryDto> queryPageList(
		PageQuery<PreparationInventoryDto> pageQuery) {
		PageList<PreparationInventoryDto> result = new PageList<PreparationInventoryDto>();
		Integer itemCount = preparationInventoryDao.count(pageQuery);
		List<PreparationInventoryDto> list = preparationInventoryDao.queryPageList(pageQuery,itemCount);
		Pagenation pagenation = new Pagenation(pageQuery.getPageNo(), itemCount, pageQuery.getPageSize());
		result.setPagenation(pagenation);
		result.setValues(list);
		return result;
	}
	
	@Override
	public Integer getMaxNo(String no) {
		return preparationInventoryDao.getMaxNo(no);
	}

	@Override
	public PreparationInventoryDto queryByNo(String barCode) {
		return preparationInventoryDao.queryByNo(barCode);
	}

	@Override
	public List<PreparationInventoryDto> queryList(PageQuery<PreparationInventoryDto> pageQuery) {
		return preparationInventoryDao.queryList(pageQuery);
	}

	@Override
	public List<PreparationInventoryDto> getToPrintList() {
		return preparationInventoryDao.getToPrintList();
	}

	@Override
	public void finishPrint(String barCode) {
		PreparationInventory preparationInventory = preparationInventoryDao.queryByNo(barCode);
		if("0".equals(preparationInventory.getPrintStatus())){
			preparationInventory.setPrintStatus("1");
			preparationInventoryDao.update(preparationInventory);
		}
	}

	@Override
	public void startPrint(String barCode) {
		PreparationInventory preparationInventory = preparationInventoryDao.queryByNo(barCode);
		if(!"0".equals(preparationInventory.getPrintStatus())){
			preparationInventory.setPrintStatus("0");
			preparationInventoryDao.update(preparationInventory);
		}
	}
	
}
